package com.zr.lads.action;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.lads.pojo.Line;
import com.zr.lads.service.LineService;
import com.zr.lads.util.PrintWriterUtil;

import net.sf.json.JSONObject;
/**
 * 
 * @author wu
 *
 */
@Controller
@Scope(value="prototype")
public class LineAction extends ActionSupport implements SessionAware,ServletRequestAware,ServletResponseAware{
    @Resource
    private LineService lineService;
    @Resource
    private  Map<String, Object> session;
    private  HttpServletResponse response;
    private  HttpServletRequest request;
   
    private  int lineId;
    private   int page;
    private   int rows;
    private   String searchname;
    private  String lineName;
    private String beginPoint;
    private String endPoint;
    private String lineIds;
    private Line line;
    
    
    public Line getLine() {
		return line;
	}

	public void setLine(Line line) {
		this.line = line;
	}

	public String getLines() {
		return lineIds;
	}

	public void setLines(String lines) {
		this.lineIds = lines;
	}

	public String getBeginPoint() {
		return beginPoint;
	}

	public void setBeginPoint(String beginPoint) {
		this.beginPoint = beginPoint;
	}

	public String getEndPoint() {
		return endPoint;
	}

	public void setEndPoint(String endPoint) {
		this.endPoint = endPoint;
	}

	
    
	
	public int getLineId() {
		return lineId;
	}

	public void setLineId(int lineId) {
		this.lineId = lineId;
	}

	public String getLineName() {
		return lineName;
	}

	public void setLineName(String lineName) {
		this.lineName = lineName;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	
    

	public String getSearchname() {
		return searchname;
	}

	public void setSearchname(String searchname) {
		this.searchname = searchname;
	}

	public void findlines(){
		
		JSONObject lines=lineService.findlines(page, rows);
		
		
		PrintWriterUtil.getPW(response).write(lines.toString());
	}
	public void  addlines(){
		Line l=new Line();
		boolean f=lineService.addlines(line);
		PrintWriterUtil.getPW(response).write(String.valueOf(f));
	}
	public void  updatelines(){
		
		boolean f=lineService.updatelines(lineId, lineName, beginPoint, endPoint);
		PrintWriterUtil.getPW(response).write(String.valueOf(f));
	}
	
	public void  deletelines(){
		boolean f=lineService.deletelines(lineIds);
		PrintWriterUtil.getPW(response).write(String.valueOf(f));
	}
	@Override
	public void setServletResponse(HttpServletResponse response) {
		// TODO Auto-generated method stub
		this.response=response;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		// TODO Auto-generated method stub
		this.request=request;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		// TODO Auto-generated method stub
		this.session=session;
	}

}
